;+
; NAME:
;       READ_RV_FLAG
;
; PURPOSE:
;       Reads the RV flags from the "has_rv_types" flag in the IDL
;       structure
;
; CATEGORY:
;       BGPS distance-omnibus Utility
;
; CALLING SEQUENCE:
;       flgarr = READ_RV_FLAG( flag )
;
; INPUTS:
;       flag -- .has_rv_types structure member for the BGPS source
;
; OPTIONAL INPUTS:
;       NONE
;
; KEYWORD PARAMETERS:
;       NONE
;
; OUTPUTS:
;       flgarr -- String array containing the names of the flags set
;
; OPTIONAL OUTPUTS:
;       NONE
;
; MODIFICATION HISTORY:
;
;       Created:  01/25/13, TPEB -- Initial version.
;
;-

FUNCTION READ_RV_FLAG, flag, nhas
  
  nhas = 0
  IF flag EQ 0 THEN RETURN,''
  names = ['HCOP','N2HP','CS21','NH3','CS54','CSUN','GRS13CO']
  hasrv = bytarr(n_elements(names))
  FOR jj=0,n_elements(names)-1 DO BEGIN
     val = 2^jj
     IF (flag AND val) NE 0 THEN hasrv[jj] = 1b
  ENDFOR
  ind = where(hasrv,nhas)
  IF nhas EQ 0 THEN BEGIN
     message,'Invalid FLAG Set!',/cont
     RETURN,''
  ENDIF
  RETURN,names[ind]
END
